package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询用户列表
     *  /users?page=1&pagesize=10
     */
    @GetMapping("/users")
    public ResponseEntity users(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult vo = manageService.findUsers(page,pagesize);
        return ResponseEntity.ok(vo);
    }

    //根据id查询用户详情
    @GetMapping("/users/{id}")
    public ResponseEntity findById(@PathVariable("id") Long id) {
        UserInfo info = manageService.findUserById(id);
        return ResponseEntity.ok(info);
    }

    /**
     * 查询用户发布的所有视频记录
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid) {
        PageResult vo = manageService.findVideosByUserId(page,pagesize,uid);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询动态列表
     *  pagesize
     *  page
     *  uid
     *  state
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid,
                                 Integer state) {
        PageResult vo = manageService.findMovementByUserId(page,pagesize,uid,state);
        return ResponseEntity.ok(vo);
    }
}
